<?php include_once dirname(__FILE__).'/common/header.php'; ?>

<?php include_once dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.group_list = <?php echo $attr['group_list']?>;
attr.group_available_list = <?php echo $attr['group_available_list'] ?>;

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.GridPanel({
	tbar:[{
		text:'新建管理员',
		cls:'btn-show',
		hidden:!Ext.permission['user/addUser'.toLowerCase()],
		iconCls:'icon-create',
		handler:function() {
			var frm = new ZM.FormPanel({
				url:list.baseUrl + 'user/addUser',
				keySubmit:false,
				success:function(res) {
					ZM.bo.msg('success',res.detail);
					list.grid.store.reload();
					win.close();
				},
				items:[{
					fieldLabel:'编码',
					name:'user_code',
					allowBlank:false
				},{
					fieldLabel:'名称',
					name:'user_name',
					allowBlank:false
				},{
					xtype:'numberfield',
					fieldLabel:'手机号',
					name:'user_phone',
					minLength:11,
					maxLength:11
				},{
					xtype:'combofield',
					fieldLabel:'角色',
					name:'group_id',
					options:attr.group_available_list,
					allowBlank:false
				}]
			});
			var win = new ZM.PopUp({
				title:'新建管理员',
				items:frm,
				type:'s'
			});
			win.show();
		}
	}],
	url: list.baseUrl + 'user/getUserList',
	columns:[
		{header:'ID',dataIndex:'user_id',hidden:true},
		{header:'编码',dataIndex:'user_code',filter:{}},
		{header:'名称',dataIndex:'user_name',filter:{}},
		{header:'手机号',dataIndex:'user_phone',width:150,filter:{}},
		{header:'角色',dataIndex:'group_id',renderer:function(val){
			return ZM.id2name(val,attr.group_list);
		},filter:{
			xtype:'combofield',
			options:[['','全部']].concat(attr.group_list)
		}},
		{header:'状态',dataIndex:'user_status',width:65,renderer:ZM.status,filter:{
			xtype:'combofield',
			options:[['','全部'],['0','禁用'],['1','激活']]
		}},
		{header:'操作',renderer:function(v,p,r){
			var str = '';
			if(ZM.id2name(r.json.group_id,attr.group_available_list)) {
				str += Ext.rd('编辑','fireEdit',r,'user/editUser');
				if(r.json.user_status == '1') {
					str += Ext.rd('重置密码','fireReset',r,'user/resetPassword');
					str += Ext.rd('禁用','fireDisable',r,'user/disableUser');
				} else {
					str += Ext.rd('激活','fireActive',r,'user/activeUser');
				}
			}
			return str;
		}}
	]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireEdit = function(r) {
	var r = r.json;
	var win = new ZM.PopUp({
		title:'编辑管理员',
		type:'s',
		items:new ZM.FormPanel({
			url:list.baseUrl + 'user/editUser',
			keySubmit:false,
			params:{user_id:r.user_id},
			success:function(res) {
				ZM.bo.msg('success',res.detail);
				list.grid.store.reload();
				win.close();
			},
			items:[{
				fieldLabel:'编码',
				name:'user_code',
				value:r.user_code,
				allowBlank:false
			},{
				fieldLabel:'名称',
				name:'user_name',
				value:r.user_name,
				allowBlank:false
			},{
				xtype:'numberfield',
				fieldLabel:'手机号',
				name:'user_phone',
				value:r.user_phone,
				minLength:11,
				maxLength:11
			},{
				xtype:'combofield',
				fieldLabel:'角色',
				name:'group_id',
				options:attr.group_available_list,
				value:r.group_id,
				allowBlank:false
			}]
		})
	}).show();
}

list.grid.fireDisable = function(r) {
	var r = r.json;
	Ext.Msg.confirm('确认?','确定要禁用管理员['+r.user_name+']?',function(btn) {
		if(btn != 'no') {
			ZM.ajax({
				url: list.baseUrl + 'user/disableUser',
				params:{user_id:r.user_id},
				mask:list.grid,
				success:function(res){
					ZM.bo.msg('success!',res.detail);
					list.grid.store.reload();
				}
			});
		}
	});
}

list.grid.fireActive = function(r) {
	var r = r.json;
	Ext.Msg.confirm('确认?','确定要激活管理员['+r.user_name+']?',function(btn) {
		if(btn != 'no') {
			ZM.ajax({
				url: list.baseUrl + 'user/activeUser',
				params:{user_id:r.user_id},
				mask:list.grid,
				success:function(res){
					ZM.bo.msg('success!',res.detail);
					list.grid.store.reload();
				}
			});
		}
	});
}

list.grid.fireReset = function(r) {
	var r = r.json;
	Ext.Msg.confirm('确认?','确定要重置管理员['+r.user_name+']的密码?',function(btn) {
		if(btn != 'no') {
			ZM.ajax({
				url: list.baseUrl + 'user/resetPassword',
				params:{user_id:r.user_id},
				mask:list.grid,
				success:function(res){
					ZM.bo.msg('success!',res.detail);
					list.grid.store.reload();
				}
			});
		}
	});
}

<?php include_once dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include_once dirname(__FILE__).'/common/footer.php'; ?>